package com.yk.faceapplication.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.allinpay.xed.R;
import com.yk.faceapplication.entity.LoanRecord;
import com.yk.faceapplication.util.FormatUtil;
import com.yk.faceapplication.util.ImageUtil;

import java.util.List;

public class RequestAccountAdapter extends BaseAdapter {
	private Context context = null;
	private List<LoanRecord> list = null;

	public RequestAccountAdapter(Context context, List<LoanRecord> list) {
		this.context = context;
		this.list = list;
	}

	@Override
	public int getCount() {
		if (list != null) return list.size();
		return 0;
	}

	@Override
	public Object getItem(int position) {
		if (list != null) list.get(position);
		return null;
	}

	@Override
	public long getItemId(int position) {
		return 0;
	}

	@Override
	public View getView(final int position, View convertView, ViewGroup parent) {
		ViewHolder viewHolder = null;
		if (convertView == null) {
			viewHolder = new ViewHolder();
			convertView = LayoutInflater.from(context).inflate(R.layout.item_request, null);
			viewHolder.img = (ImageView) convertView.findViewById(R.id.pro_img);
			viewHolder.title = (TextView) convertView.findViewById(R.id.pro_title);
			viewHolder.content = (TextView) convertView.findViewById(R.id.pro_content);
			viewHolder.des = (TextView) convertView.findViewById(R.id.pro_des);
			convertView.setTag(viewHolder);
		}
		else {
			viewHolder = (ViewHolder) convertView.getTag();
		}
		if(list.get(position).getProductIconId() != null){
			ImageUtil.displayImage(context, list.get(position).getProductIconId(), viewHolder.img);
		}else{
			viewHolder.img.setImageDrawable(null);
		}

		viewHolder.title.setText(list.get(position).getLoanProductName()==null?"":list.get(position).getLoanProductName());
		// viewHolder.lable.setText(list.get(position).getPrdLable());
		//		viewHolder.content.setText(list.get(position).getPrdNote());
		String rateType = "";
		switch (list.get(position).getTermType()) {
			case "D":
				rateType = "日";
				break;
			case "M":
				rateType = "月";
				break;
			case "Y":
				rateType = "年";
				break;
		}
		viewHolder.content.setText("申请金额:" + list.get(position).getLoanAmt() + "元    期限:"+list.get(position).getLoanTerm()+rateType );
		viewHolder.des.setText("申请日期:" +FormatUtil.long2String(list.get(position).getApplicationTime()));
		return convertView;
	}

	class ViewHolder {
		private ImageView img = null;
		private TextView title = null;
		private TextView content = null;
		private TextView des = null;
	}

}
